const auth = require('./utils/auth');

App({
  globalData: {
    animationDisabled: false,
    isAuthenticated: false,
    userInfo: null
  },

  onLaunch() {
    const animationDisabled = wx.getStorageSync('animationDisabled');
    if (typeof animationDisabled === 'boolean') {
      this.globalData.animationDisabled = animationDisabled;
    }

    // 初始化认证状态
    this.updateAuthState();
  },

  /**
   * 更新全局认证状态
   */
  updateAuthState() {
    this.globalData.isAuthenticated = auth.checkAuth();
    this.globalData.userInfo = auth.getUserInfo();
  },

  /**
   * 设置认证状态
   */
  setAuthState(isAuthenticated, userInfo = null) {
    this.globalData.isAuthenticated = isAuthenticated;
    this.globalData.userInfo = userInfo;
  },

  setAnimationDisabled(disabled) {
    const value = !!disabled;
    this.globalData.animationDisabled = value;
    wx.setStorageSync('animationDisabled', value);
  }
});

